package cn.mldn.mldncloud.service.impl;

import cn.mldn.mldncloud.dao.IRidersDAO;
import cn.mldn.mldncloud.dto.RidersDTO;
import cn.mldn.mldncloud.po.Riders;
import cn.mldn.mldncloud.service.IRidersService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RidersServiceImpl implements IRidersService {

    @Autowired
    private IRidersDAO ridersDAO;                    // 注入DAO接口对象

    @Override
    public RidersDTO get(long ridersId) {
        System.err.println("################");
        System.err.println("################");
        Riders po = this.ridersDAO.getOne(ridersId);
        RidersDTO dto = new RidersDTO();
        BeanUtils.copyProperties(po, dto);
        return dto;
    }

    @Override
    public List<RidersDTO> list() {
    	System.err.println("调用servie服务");
		System.err.println("调用servie服务");
		System.err.println("调用servie服务");
		System.err.println("调用servie服务");
		System.err.println("调用servie服务");
        System.err.println("################");
        System.err.println("################");
        List<Riders> allRiders = this.ridersDAO.findAll();
        List<RidersDTO> returnRiders = new ArrayList<>();
        allRiders.forEach((riders) -> {
            RidersDTO dto = new RidersDTO();
            BeanUtils.copyProperties(riders, dto);
            returnRiders.add(dto);
        });
        return returnRiders;
    }
}
